<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.util.*,util.*,dal.*,model.*,bll.*"%>
<%
	ProjectModel obj;
	Object temp = request.getAttribute("project");
	if (temp != null) {
		try {
			obj = (ProjectModel) temp;
		} catch (Exception ex) {
			obj = new ProjectModel();
		}
	} else {
		obj = new ProjectModel();
	}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Project</title>
<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/inputForm.css" />
<link rel="stylesheet" href="css/listForm.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-datepicker.css" />
<link rel="stylesheet" href="css/jquery-dialog.css" />

<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.widget.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript" src="js/ajaxQuickInsert.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.numeric.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.tools.min.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>

<script language="javascript" type="text/javascript">
	$(document).ready(pagedLoaed);
	
	function pagedLoaed()
	{
		turnOnNumbericInput();
		initDatePicker();
		initTooltip();
	} 
	var requiredInputs = [['name','name_required'],['plan_start_date_date','plan_start_date_date_required'],['plan_end_date_date','plan_end_date_date_required']];
//	var intInputs = [];
//	var doubleInputs = [];
	var dateInputs = [['plan_start_date_date','plan_start_date_date_invalid'],['plan_end_date_date','plan_end_date_date_invalid']];
//	var timeInputs = [];
	function checkInputs() {
		var valid = true;

		if (checkRequiredInputs(requiredInputs) == false) {
			valid = false;
		}
// 		if (checkIntInputs(intInputs) == false) {
// 			valid = false;
// 		}
// 		if (checkDoubleInputs(doubleInputs) == false) {
// 			valid = false;
// 		}
		if (checkDateInputsForCorrectedFormatOnly(dateInputs, dateFormat) == false) {
			valid = false;
		}
// 		if (checkTimeInputs(timeInputs) == false) {
// 			valid = false;
// 		}

		// SPECIFIC VALIDATE CODE HERE		

		return valid;
	}
	
	
</script>
</head>
<body>
	<div class="divContainer">
		<%@ include file="menu.jsp"%>
		<form id="inputForm" action="project?mode=update" method="post" onSubmit="return checkInputs();" onreset="return confirm('Do you really want to reset the form?');">
			<table class="tblInput">
				<tr >
					<td class="inputHeader">Edit Project</td>
				</tr>
				<tr>
					<td style="padding-left: 400px; padding-right: 400px;">
						<table cellspacing="0px">
						<tr class="trField">
							<td class="tdFieldName">Id</td>
							<td class="tdFieldInput"><input class="inputInt readonly" type="text" id="id" name="id" readonly="readonly" value="<%=obj.getId()%>" title="The project Id. It's readonly."/></td>
							<td class="tdErrMsg"></td>
						<tr class="trField">
							<td class="tdFieldName">Name</td>
							<td class="tdFieldInput"><input class="inputText" title="Project name. Note: Required." type="text" id="name" name="name" maxlength="255" value="<%=obj.getNameToString()%>" onblur="validateRequiredInput('name');"/>
							</td>
							<td class="tdErrMsg">
								<span id="name_required" class="errMsg" style="display: none;" title="Name is required">(!)</span> 
								<span id="name_invalid" class="errMsg" style="display: none;" title="Invalid name">(!)</span> 
								<span id="name_error" class="errMsg"><%=obj.errMsgs.Name%></span></td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Description</td>
							<td class="tdFieldInput"><textarea id="description" title="Description for the project." name="description" rows="5" class="inputTextarea"><%=obj.getDescription()%></textarea></td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Project Manager</td>
							<td class="tdFieldInput"><select id="pm" name="pm" class="hyjack">
									<%=HtmlUtil.<EmployeeModel>genModelSelect(CacheUtil.getEmployeeList(), null, obj.getPm(), false, true)%>
							</select> <input class="btnAdd" type="button" id="addNewPm" value="" onclick="ajaxAddItem('#pm', 'employee', 'name', 'Please enter new project manager name!');" title="Click to add new employee." />
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Status</td>
							<td class="tdFieldInput">
								<select id="status" name="status" title="Select one status for this project." class="hyjack">
									<%=HtmlUtil.genEnumSelect(EnumName.ProjectStatus, null, obj.getStatus())%>
								</select>
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Company</td>
							<td class="tdFieldInput"><select id="id_company" name="id_company" class="hyjack" title="Choose a company for the project.">
									<%=HtmlUtil.<CompanyModel> genModelSelect(CacheUtil.getCompanyList(), null, obj.getIdCompany())%>
							</select> <input class="btnAdd" type="button" id="addNewIdCompany" value="" onclick="ajaxAddItem('#id_company', 'company', 'short_name', 'Please enter your company short name!');" title="Click to add new compnay." title="Click here to add new company." />
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr>
						<td class="tdFieldName">Budget</td>
						<td class="tdFieldInput">
							<input class="inputNumeric" type="text" id="budget" name="budget" value="<%=obj.getBudgetToString() %>" title="Project budget. <br/>Note: numeric only." maxlength="20"/>
						</td>
						<td class="tdErrMsg">
						</td>				
					</tr>
						<tr class="trField">
							<td class="tdFieldName">Attendees</td>
							<td class="tdFieldInput"><input class="inputInt" type="text" title="Number of attendee. Note: Only number allowed!" id="attendees" name="attendees" maxlength="10" value="<%=(obj.getAttendeesToString())%>" />
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Venue</td>
							<td class="tdFieldInput"><select id="id_venue" name="id_venue" class="hyjack">
									<%=HtmlUtil.<VenueModel> genModelSelect(CacheUtil.getVenueList(), null, obj.getIdVenue())%>
							</select>
							<input class="btnAdd" type="button" id="addNewIdCompany" value="" onclick="ajaxAddItem('#id_venue', 'venue', 'name', 'Please enter new venue name!');"  title="Click here to add new venue." />
							</td>
							<td class="tdErrMsg"></td>
						</tr>
						
						<tr class="trField">
							<td class="tdFieldName">Plan Start Date</td>
							<td class="tdFieldInput">
								<input type="text" maxlength="10"  title="Click to choose plan start date. Note: Required."
											class="inputDate" id="plan_start_date_date"
											name="plan_start_date_date"
											value="<%=StringUtil.toDateString(obj.getPlanStartDate())%>"  onblur="validateRequiredInput('plan_start_date_date',false);" onchange="validateDateInput('plan_start_date_date',true)"/>
								<span class="textGuide"> (dd/mm/yyyy)</span>				
							</td>
							<td class="tdErrMsg">
								<span id="plan_start_date_error" class="errMsg"><%=obj.errMsgs.PlanStartDate%></span>
								<span id="plan_start_date_date_required" class="errMsg" style="display: none;" title="Plan start date is required">(!)</span>
								<span id="plan_start_date_date_invalid" class="errMsg" style="display: none;" title="You've entered an invalid date.<br/>The format is <b>dd/mm/yyyy</b>">(!)</span>
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Plan End Date</td>
							<td class="tdFieldInput">
								<input type="text" maxlength="10"  title="Click to choose plan end date. Note: Required."
											class="inputDate" id="plan_end_date_date"
											name="plan_end_date_date"
											value="<%=StringUtil.toDateString(obj.getPlanEndDate())%>"  onblur="validateRequiredInput('plan_end_date_date',false);" onchange="validateDateInput('plan_end_date_date',true)"/>
								<span class="textGuide"> (dd/mm/yyyy)</span>												
							</td>
							<td class="tdErrMsg">
								<span id="plan_end_date_error" class="errMsg"><%=obj.errMsgs.PlanEndDate%></span>
								<span id="plan_end_date_date_required" class="errMsg" style="display: none;" title="Plan end date is required">(!)</span>
								<span id="plan_end_date_date_invalid" class="errMsg" style="display: none;" title="You've entered an invalid date. The format is <b>dd/mm/yyyy</b>">(!)</span>
							</td>
						</tr>
						<tr>
							<td></td>
							<td class="tdFieldInput">
								<a href="teamAllocationNew.jsp?idProject=<%=obj.getId()%>&sentFrom=edit" title="Click to edit team member!"><img src="images-interface/user_group.png"/> &nbsp;Team Allocation</a>
							</td>
							<td></td>
						</tr>
						<tr class="trInputBottom">
							<td class="tdFieldName"></td>
							<td class="tdSubmit"><input class="btnSubmit" type="submit" value="Submit" title="Click to save above information."/></td>
<!-- 							<td class="tdInputBottom" colspan="3"> -->
<!-- 								<table class="tblSubmit" align="left"> -->
<!-- 									<tr class="trSubmit"> -->
<!-- 										<td class="tdSubmit"><input class="btnSubmit" type="submit" value="Submit" title="Click to save above information."/></td> -->
<!-- 									</tr> -->
<!-- 								</table></td> -->
						</tr>
						</table>
					</td></tr>
					</table>
				</form>
				<%
					String embeddedPage = "projectList.jsp?embedded=true";
				%>
		<jsp:include page="<%=embeddedPage%>"></jsp:include>
	</div>
</body>
</html>